package com.hxzy.service.impl;

import com.hxzy.util.MybatisUtil;
import com.hxzy.dto.BuildDTO;
import com.hxzy.entity.Build;
import com.hxzy.mapper.BuildMapper;
import com.hxzy.service.BuildService;
import com.hxzy.vo.BuildVo;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Description:
 * @Author: ykj
 * @Date: 2022/3/8 17:29
 */
public class BuildServiceImpl implements BuildService {
    @Override
    public int insert(Build build) {
        int count=-1;
        try (SqlSession sqlSession= MybatisUtil.getSqlSessionFactory().openSession()){
            BuildMapper mapper = sqlSession.getMapper(BuildMapper.class);
            count = mapper.insert(build);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public int update(Build build) {
        int count=-1;
        try (SqlSession sqlSession= MybatisUtil.getSqlSessionFactory().openSession()){
            BuildMapper mapper = sqlSession.getMapper(BuildMapper.class);
            count=mapper.update(build);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public int delete(String id) {
        int count=-1;
        try (SqlSession sqlSession= MybatisUtil.getSqlSessionFactory().openSession()){
            BuildMapper mapper = sqlSession.getMapper(BuildMapper.class);
            count=mapper.delete(id);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public Build findOne(String id) {
        Build build=null;
        try (SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            BuildMapper mapper = sqlSession.getMapper(BuildMapper.class);
            build = mapper.findOne(id);
        }
        return build;
    }

    @Override
    public List<BuildVo> search(BuildDTO buildDTO) {
        List<BuildVo> list=null;
        try (SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            BuildMapper mapper = sqlSession.getMapper(BuildMapper.class);
            list = mapper.search(buildDTO);
        }
        return list;
    }
}
